View Javadoc

1   /*
2   
3   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by the
7   Free Software Foundation; either version 2 of the License, or (at your
8   option) any later version.
9   
10  This program is distributed in the hope that it will
11  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13  PURPOSE. See the GNU General Public License for more details.
14  
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc., 59
17  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  
19  */
20  package org.devaki.nextobjects.workspace.models.objects;
21  import java.io.Serializable;
22  import java.util.Vector;
23  import org.devaki.nextobjects.workspace.models.ConceptualModel;
24  import org.devaki.nextobjects.workspace.models.columns.Column;
25  import org.devaki.nextobjects.workspace.models.graphics.EntityView;
26  import org.devaki.nextobjects.workspace.models.graphics.ObjectView;
27  /***
28   * The entities in the merise model
29   * @see http://www.devaki.org/cdm.html
30   */
31  public class Entity extends BaseClass implements Serializable
32  {
33      /***
34       *
35       * the subsequent Table deduced in a Merise Transformation
36       */
37      private transient Table subSequentTable;
38      /***
39       *  The EntityView
40       *
41       */
42      private EntityView entityView;
43      /***
44       * Construct a new 'Entity' object
45       * @param pObject the entity to clone
46       */
47      public Entity(final Entity pObject)
48      {
49          super(pObject);
50          this.entityView = new EntityView(this);
51      }
52      /***
53       * Construct a new 'Entity' object
54       * @param pModel the context model
55       */
56      public Entity(final ConceptualModel pModel)
57      {
58          super(pModel);
59          this.setName(
60              new StringBuffer()
61                  .append("Entity ")
62                  .append(pModel.countEntities())
63                  .toString());
64          this.setCode(
65              new StringBuffer()
66                  .append("Entity")
67                  .append(pModel.countEntities())
68                  .toString());
69          this.entityView = new EntityView(this);
70      }
71      /***
72       * Return the first Primary key
73       * @return the column
74       */
75      public final Column getIdentifier()
76      {
77          Vector columns = this.getColumns();
78          Column tmpPk = null;
79          for (int i = 0; i < columns.size(); i++)
80          {
81              if (((Column) columns.elementAt(i)).isPk())
82              {
83                  tmpPk = (Column) columns.elementAt(i);
84                  break;
85              }
86          }
87          return tmpPk;
88      }
89      /***
90       * Return all Primary key
91       * @return the primary jeys
92       */
93      public final Vector getAllIdentifier()
94      {
95          Vector tmpVect = new Vector();
96          Vector columns = this.getColumns();
97          Column tmpPk = null;
98          for (int i = 0; i < columns.size(); i++)
99          {
100             if (((Column) columns.elementAt(i)).isPk())
101             {
102                 tmpPk = (Column) columns.elementAt(i);
103                 tmpVect.add(tmpPk);
104             }
105         }
106         return tmpVect;
107     }
108     /***
109      * Get the subsequent table in a pdm
110      * @return the table
111      */
112     public final Table getSubsequentTable()
113     {
114         return this.subSequentTable;
115     }
116     /***
117      * Return the entity view
118      * @return the object view
119      */
120     public final ObjectView getObjectView()
121     {
122         return this.entityView;
123     }
124     /***
125      * Set the subsequent table
126      * @param pTable the table
127      */
128     public final void setSubsequentTable(final Table pTable)
129     {
130         this.subSequentTable = pTable;
131     }
132 }